home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / x11 / networke / xfirepow.000 / xfirepow / xfirepower-0.84 / common / packet.h < prev    next >
C/C++ Source or Header  |  1995-11-22  |  6KB  |  288 lines

  1. /* packet.h for firepower
  2.  
  3.    Contains definitions of all the packet types for both directions.
  4.  
  5.    Packets the server sends start with s_
  6.    Packets the client sends start with c_
  7.  
  8.    */
  9.  
  10. #ifndef packet_h
  11. #define packet_h
  12.  
  13. #include "defs.h"
  14. typedef unsigned char UCHAR;
  15. typedef char CHAR;
  16. typedef short SHORT;
  17. typedef unsigned short USHORT;
  18. typedef int INT;
  19. typedef unsigned int UINT;
  20.  
  21. enum s_packet_types {
  22.     S_NULL,
  23.     S_MAPINFO,
  24.     S_PLAYERINFO,
  25.     S_POSITIONS,
  26.     S_PERSONAL,
  27.     S_LOGIN,
  28.     S_SHELL,
  29.     S_MESSAGE,
  30.     S_PLAYERDATA,
  31.     S_PLAYERSTATS,
  32.     S_SHELLINFO,
  33.     S_MAPSQUARE,
  34.     S_FLAG,
  35.     S_UDPREPLY,
  36.     S_MOTDLINE,
  37.     S_TEAMOK,
  38.     S_MINE,
  39.     S_PING
  40. };
  41.  
  42. /* mapinfo - the header for the map, but not the raw data */
  43. typedef struct {
  44.     UCHAR type;                 /* S_MAPINFO */
  45.     UCHAR width, height;
  46.     UCHAR pad;
  47.     CHAR name[32];
  48.  
  49.     /* data goes here, width x height array of bytes */
  50. } s_mapinfo;
  51.  
  52. /* playerinfo, status and team a player belongs to */
  53. typedef struct {
  54.     UCHAR type;                 /* S_PLAYERINFO */
  55.     UCHAR num;
  56.     UCHAR status, team;
  57. } s_playerinfo;
  58.  
  59. /* one s_position followed by multiple s_oneposition packets send the coords of every
  60.    player */
  61. typedef struct {
  62.     UCHAR type;                 /* S_POSITIONS */
  63.     UCHAR num;                  /* how many players contained in this packet, MSB = tactical or strategic */
  64.     UCHAR pad1, pad2;
  65. } s_positions;
  66.  
  67. typedef struct {                /* not a packet by itself, combined with s_positions */
  68.     UCHAR num, lx, ly, dir;
  69. } s_oneposition;
  70.  
  71. typedef struct {                /* Info only for the player being sent to */
  72.     UCHAR type;                 /* S_PERSONAL */
  73.     UCHAR status;
  74.     USHORT x, y;                /* coords */
  75.  
  76.     UCHAR dir;                  /* heading */
  77.     UCHAR damage;               /* How hurt you are.  0 = full strength, 255 = dead */
  78.     UCHAR ammo;                 /* how many shells you have left */
  79.     UCHAR mines;                /* only need 3 bits of this (with <= 8 MINESPERPLAYER) */
  80.     USHORT fuel;                /* amount of fuel left */
  81. } s_personal;
  82.  
  83. typedef struct {
  84.     UCHAR type;                 /* S_LOGIN */
  85.     UCHAR num;                  /* who you are */
  86.     UCHAR pad1, pad2;
  87. } s_login;
  88.  
  89. /* shell: sends just coords for a shell */
  90. typedef struct {
  91.     UCHAR type;                 /* S_SHELL */
  92.     UCHAR num;
  93.     UCHAR lx, ly;
  94. } s_shell;
  95.  
  96. /* message: used for all text messages, including warnings currently */
  97. typedef struct {
  98.     UCHAR type;                 /* S_MESSAGE */
  99.     UCHAR from;
  100.     UCHAR to;
  101.     UCHAR flags;
  102.     CHAR message[80];
  103. } s_message;
  104.  
  105. /* playerdata: sends the name of a particular player */
  106. typedef struct {
  107.     UCHAR type;
  108.     UCHAR num;
  109.     UCHAR pad1, pad2;
  110.     CHAR name[16];
  111. } s_playerdata;
  112.  
  113. /* playerstats: sends wins, losses, kills for a player
  114.    wins = total number of tanks killed
  115.    losses = total number of times he's died
  116.    kills = tanks killed since the last time he died
  117.    */
  118. typedef struct {
  119.     UCHAR type;
  120.     UCHAR num;
  121.     UCHAR pad1, pad2;
  122.     UINT wins;
  123.     UINT losses;
  124.     UINT kills;
  125. } s_playerstats;
  126.  
  127. /* shellinfo: status of a shell (not coords) */
  128. typedef struct {
  129.     UCHAR type;
  130.     UCHAR num;
  131.     UCHAR status;
  132.     UCHAR pad;
  133. } s_shellinfo;
  134.  
  135. /* sends the terrain for a single map square */
  136. typedef struct {
  137.     UCHAR type;
  138.     UCHAR x, y;
  139.     UCHAR value;
  140. } s_mapsquare;
  141.  
  142. /* flag: sends the location and team of a particular flag */
  143. typedef struct {
  144.     UCHAR type;
  145.     UCHAR num;
  146.     UCHAR team;
  147.     UCHAR pad;
  148.     USHORT x;
  149.     USHORT y;
  150. } s_flag;
  151.  
  152. #define MODE_UDP 1
  153. #define MODE_TCP 2
  154. #define SWITCH_DENIED 1
  155. #define SWITCH_UDP_OK 2
  156.  
  157. /* udpreply: sent when a player requests a UDP connection (or requests it be closed) */
  158. typedef struct {
  159.     UCHAR type;
  160.     UCHAR reply;
  161.     USHORT port;
  162. } s_udpreply;
  163.  
  164. /* sends one line of the motd */
  165. typedef struct {
  166.     UCHAR type;
  167.     UCHAR pad;
  168.     USHORT line;
  169.     CHAR text[80];
  170. } s_motdline;
  171.  
  172. /* sends a verification that the team a player wants to join is ok or not */
  173. typedef struct {
  174.     UCHAR type;
  175.     UCHAR teamok;
  176.     UCHAR pad1, pad2;
  177. } s_teamok;
  178.  
  179. /* sends a mine's status & location */
  180. typedef struct {
  181.     UCHAR type;
  182.     UCHAR status;
  183.     USHORT num;
  184.     USHORT x, y;
  185. } s_mine;
  186.  
  187. /* reply to a client's request for a ping (lag timing) */
  188. typedef struct {
  189.     UCHAR type;
  190.     UCHAR seq;
  191.     UCHAR pad1, pad2;
  192. } s_ping;
  193.  
  194. enum c_packet_types {
  195.     C_NULL,
  196.     C_LOGIN,
  197.     C_STEERING,
  198.     C_SHELL,
  199.     C_MESSAGE,
  200.     C_SPEED,
  201.     C_COURSE,
  202.     C_UDPREQUEST,
  203.     C_TEAM,
  204.     C_MINE,
  205.     C_BUILD,
  206.     C_PING
  207. };
  208.  
  209. /* send the player's name, login, and client version to the server */
  210. typedef struct {
  211.     UCHAR type;                 /* C_LOGIN */
  212.     UCHAR pad1;
  213.     USHORT version;
  214.     CHAR name[16];
  215.     CHAR login[16];
  216. } c_login;
  217.  
  218. /* obsolete, c_course is current */
  219. typedef struct {
  220.     UCHAR type;                 /* C_STEERING */
  221.     UCHAR keys;
  222.     UCHAR pad1, pad2;
  223. } c_steering;
  224.  
  225. /* player wants to fire a shell */
  226. typedef struct {
  227.     UCHAR type;                 /* C_SHELL*/
  228.     UCHAR pad1, pad2, pad3;     /* Just the packet itself is enough info. */
  229. } c_shell;
  230.  
  231. /* player sent a message */
  232. typedef struct {
  233.     UCHAR type;                 /* C_MESSAGE */
  234.     UCHAR to;
  235.     USHORT flags;
  236.     CHAR message[80];
  237. } c_message;
  238.  
  239. /* player wants to change his speed */
  240. typedef struct {
  241.     UCHAR type;
  242.     CHAR speed;
  243.     UCHAR pad1, pad2;
  244. } c_speed;
  245.  
  246. /* player wants to change course */
  247. typedef struct {
  248.     UCHAR type;
  249.     UCHAR dir;
  250.     UCHAR pad1, pad2;
  251. } c_course;
  252.  
  253. /* player wants to open or close his UDP connection */
  254. typedef struct {
  255.     UCHAR type;
  256.     UCHAR mode;
  257.     USHORT port;
  258. } c_udprequest;
  259.  
  260. /* player wants to join this team */
  261. typedef struct {
  262.     UCHAR type;
  263.     UCHAR team;
  264.     UCHAR pad1, pad2;
  265. } c_team;
  266.  
  267. /* player wants to lay a mine */
  268. typedef struct {
  269.     UCHAR type;
  270.     UCHAR pad1, pad2, pad3;     /* don't need any info, just getting the packet is enough */
  271. } c_mine;
  272.  
  273. /* player wants to build something */
  274. typedef struct {
  275.     UCHAR type;
  276.     UCHAR terrain;
  277.     UCHAR pad1, pad2;
  278. } c_build;
  279.  
  280. /* player wants to check out his lag */
  281. typedef struct {
  282.     UCHAR type;
  283.     UCHAR seq;
  284.     UCHAR pad1, pad2;
  285. } c_ping;
  286.  
  287. #endif
  288.